package com.dyb.recuitment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dyb.recuitment.entity.JobComment;
import com.dyb.recuitment.entity.JobLike;
import com.dyb.recuitment.mapper.JobCommentMapper;
import com.dyb.recuitment.service.IJobCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 岗位评论表 服务实现类
 * </p>
 *
 * @author 邓宇斌
 * @since 2022-02-22
 */
@Service
public class JobCommentServiceImpl extends ServiceImpl<JobCommentMapper, JobComment> implements IJobCommentService {

    @Autowired
    private JobCommentMapper jobCommentMapper;

    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Override
    public int add(JobComment jobComment) {
        LocalDateTime localDateTime = LocalDateTime.parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), df);
        jobComment.setCreateTime(localDateTime).setUpdateTime(localDateTime);
        return jobCommentMapper.insert(jobComment);
    }

    @Override
    public int delete(JobComment jobComment) {
        LocalDateTime localDateTime = LocalDateTime.parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), df);
        jobComment.setStatus(0).setUpdateTime(localDateTime);
        return jobCommentMapper.updateById(jobComment);
    }

    @Override
    public List<JobComment> selectByJobComment(JobComment jobComment) {
        jobComment.setStatus(1);
        QueryWrapper<JobComment> queryWrapper = new QueryWrapper<>(jobComment);
        return jobCommentMapper.selectList(queryWrapper);
    }

    @Override
    public List<JobComment> selectAllJobComment() {
        return jobCommentMapper.selectList(new QueryWrapper<>());
    }

}
